var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2Hts = require("Hts");
var $2AudioManager = require("AudioManager");
var $2BundleManager = require("BundleManager");
var $2DataManager = require("DataManager");
var $2ExcelManager = require("ExcelManager");
var $2PlantMgr = require("PlantMgr");
var $2UIManager = require("UIManager");
var $2UserDataManager = require("UserDataManager");
var $2TaSdk = require("TaSdk");
var $2KDefine = require("KDefine");
var $2MyUtils = require("MyUtils");
var $2SharePanelUI = require("SharePanelUI");
var $2TryPanelUI = require("TryPanelUI");
var $2pvzChannel = require("pvzChannel");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_SuccessBowlingUI = /* */function (_cc$Component70) {
  babel_inherits(b, _cc$Component70);
  var _super86 = babel_createSuper(b);
  function b() {
    var _this198;
    babel_classCallCheck(this, b);
    _this198 = _super86.apply(this, arguments);
    _this198.rewardGet = false;
    _this198.levelId = 1;
    _this198.rewardArray = [{
      gold: 0,
      diamond: 0,
      chip: [1, 0]
    }, {
      gold: 0,
      diamond: 0,
      chip: [1, 0]
    }, {
      gold: 0,
      diamond: 0,
      chip: [1, 0]
    }];
    _this198.bg5 = null;
    return _this198;
  }
  babel_createClass(b, [{
    key: "onLoad",
    value: function onLoad() {
      this.bg5 = cc.find("bg5", this.node);
      this.levelId = 1;
      this.rewardConfig = $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.levelTable)[this.levelId].rewardConfig;
      0 == $2DataManager.default.instance.level && ($2DataManager.default.instance.level = 1);
      $2DataManager.default.instance.clearTempData();
      $2AudioManager.default.instance.playMusic($2KDefine.AudioName.SuccessBgm);
      this.rewardGet = true;
      $2MyUtils.MyUtils.removeArrElement($2DataManager.default.instance.tryPlant, 20);
      if ($2DataManager.default.instance.level == $2UserDataManager.default.instance.level && (20 == $2DataManager.default.instance.level ? $2DataManager.default.instance.newChapter = true : $2DataManager.default.instance.focus = true, 0 != $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.levelTable)[this.levelId].firstReward)) {
        var _e105 = $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.levelTable)[this.levelId].firstReward;
        if (_e105) {
          $2UserDataManager.default.instance.getPlant(_e105);
          $2DataManager.default.instance.lockPlant = _e105;
          $2DataManager.default.instance.newPlant.includes(_e105) || $2DataManager.default.instance.newPlant.push(_e105);
        } else {
          $2UserDataManager.default.instance.setPlantChip(_e105, $2PlantMgr.default.instance().getPlant(_e105).merge);
        }
      }
      this.rewardPanel = this.node.getChildByName("Panel").getChildByName("RewardPanel");
      this.constPanel = this.node.getChildByName("Panel").getChildByName("ConstReward");
      this.btnPanel = this.node.getChildByName("Panel").getChildByName("BtnPanel");
      this.btnPanel.active = false;
      this.initPlatform();
      if ($2UserDataManager.default.instance.drawGuide || 2 != $2DataManager.default.instance.level) {
        if ($2UserDataManager.default.instance.newUser) {
          this.btnPanel.getChildByName("GetAll").getChildByName("GuideFinger").active = true;
          this.btnPanel.getChildByName("GetAll").getChildByName("Label").x = 0;
          this.btnPanel.getChildByName("GetAll").getChildByName("VideoBtn").active = false;
          this.btnPanel.getChildByName("GetOne").active = false;
          this.btnPanel.getChildByName("GetAll").x = 0;
          this.initReward();
        } else {
          this.showTryPlant();
          this.initReward();
        }
      } else {
        this.rewardArray[0].diamond = 20;
        this.rewardArray[1].gold = 3200;
        this.rewardArray[2].diamond = 20;
        this.btnPanel.getChildByName("GetAll").getChildByName("GuideFinger").active = true;
        this.btnPanel.getChildByName("GetAll").getChildByName("Label").x = 0;
        this.btnPanel.getChildByName("GetAll").getChildByName("VideoBtn").active = false;
        this.btnPanel.getChildByName("GetOne").active = false;
        this.btnPanel.getChildByName("GetAll").x = 0;
        $2UserDataManager.default.instance.diamond += 20;
        $2Hts.default.instance.eventReport("第二关通关");
        $2TaSdk.default.instance.postEvent("Tutorial", {
          tutorial_step: 14
        });
      }
      3 != $2DataManager.default.instance.level || $2UserDataManager.default.instance.bossGuide || ($2DataManager.default.instance.bossGuide = true);
      this.selectID = 0;
      $2TaSdk.default.instance.AdsExposure($2TaSdk.VideoIndex.successVideo);
    }
  }, {
    key: "initPlatform",
    value: function initPlatform() {
      $2pvzChannel.pvzChannel.instance().recorderStop();
      $2UIManager.default.instance.openUI("SharePanelUI", 40).getComponent($2SharePanelUI.default).init(0);
    }
  }, {
    key: "showTryPlant",
    value: function showTryPlant() {
      var e = [];
      for (var _t68 = 0; _t68 < $2DataManager.default.instance.selectPlantID.length; _t68++) {
        $2UserDataManager.default.instance.plantLock.includes($2DataManager.default.instance.selectPlantID[_t68]) || e.push($2DataManager.default.instance.selectPlantID[_t68]);
      }
      $2MyUtils.MyUtils.removeArrElement(e, 20);
      0 != e.length && $2UserDataManager.default.instance.freePlant < 2 && $2MyUtils.MyUtils.probability(this.tryProbability) && $2UIManager.default.instance.openUI("TryPanelUI", 30).getComponent($2TryPanelUI.default).init(e);
    }
  }, {
    key: "start",
    value: function start() {
      var _this199 = this;
      this.node.getChildByName("Panel").getComponent(cc.Animation).play();
      this.node.getChildByName("Panel").getComponent(cc.Animation).on("stop", function () {
        _this199.node.getChildByName("Panel").getChildByName("GetBtn").active = true;
        _this199.bg5.active = false;
        _this199.bg5.setPosition(_this199.node.getChildByName("Panel").getChildByName("GetBtn").x + 230, _this199.node.getChildByName("Panel").getChildByName("GetBtn").y);
      });
    }
  }, {
    key: "onClickGet",
    value: function onClickGet() {
      this.onClickGetOne();
    }
  }, {
    key: "playAnimation",
    value: function playAnimation() {
      var _this200 = this;
      this.node.getChildByName("Panel").getChildByName("RewardPanel").active = true;
      this.node.getChildByName("Panel").getChildByName("GetBtn").active = false;
      this.node.getChildByName("Panel").getChildByName("Title").active = false;
      this.node.getChildByName("Panel").getChildByName("ConstReward").active = false;
      this.rewardPanel.getComponent(cc.Animation).play("SuccessUI");
      this.rewardPanel.getComponent(cc.Animation).on("stop", function () {
        _this200.rewardPanel.getComponent(cc.Animation).off("stop");
        _this200.rewardPanel.getComponent(cc.Animation).play();
        _this200.rewardPanel.getComponent(cc.Animation).on("stop", function () {
          for (var _e106 = 0; _e106 < _this200.rewardPanel.childrenCount; _e106++) {
            _this200.rewardPanel.children[_e106].getChildByName("Title").active = true;
            _this200.rewardPanel.children[_e106].getChildByName("Title").getComponent(cc.Animation).play(null, .1 * _e106);
            _this200.rewardGet = false;
          }
          _this200.node.getChildByName("Panel").getChildByName("TitleLabel").active = true;
        });
      });
    }
  }, {
    key: "initReward",
    value: function initReward() {
      var e = 1;
      20 == $2DataManager.default.instance.level && (e = 1 == $2DataManager.default.instance.bossLevel ? .2 : 2 == $2DataManager.default.instance.bossLevel ? 1 : 5);
      for (var _n57 = 0; _n57 < this.rewardPanel.childrenCount; _n57++) {
        var _t69 = undefined;
        var _a56 = 0;
        var _i15 = Math.random();
        var _s12 = this.rewardConfig[0];
        for (; _i15 > _s12;) {
          _a56++;
          _s12 += this.rewardConfig[_a56];
        }
        switch (_a56) {
          case 0:
            _t69 = 100 * $2MyUtils.MyUtils.getRandomInt(10 + 2 * this.levelId, 21 + 4 * this.levelId) * $2UserDataManager.default.instance.chapter;
            _t69 = Math.ceil(_t69 * e);
            this.rewardArray[_n57].gold = _t69;
            this.rewardPanel.children[_n57].getChildByName("AwardPanel").getChildByName("Icon").getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ui/a034", cc.SpriteFrame);
            this.rewardPanel.children[_n57].getChildByName("AwardPanel").getChildByName("chip").active = false;
            this.rewardPanel.children[_n57].getChildByName("AwardPanel").getChildByName("desc").getComponent(cc.Label).string = "金币";
            this.rewardPanel.children[_n57].getChildByName("AwardPanel").getChildByName("desc").color = cc.color(0, 199, 255);
            break;
          case 1:
            _t69 = $2MyUtils.MyUtils.getRandomInt(10 + 2 * this.levelId, 21 + 4 * this.levelId) * $2UserDataManager.default.instance.chapter;
            _t69 = Math.ceil(_t69 * e);
            this.rewardArray[_n57].diamond = _t69;
            this.rewardPanel.children[_n57].getChildByName("AwardPanel").getChildByName("Icon").getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ui/a033", cc.SpriteFrame);
            this.rewardPanel.children[_n57].getChildByName("AwardPanel").getChildByName("chip").active = false;
            this.rewardPanel.children[_n57].getChildByName("AwardPanel").getChildByName("desc").getComponent(cc.Label).string = "钻石";
            this.rewardPanel.children[_n57].getChildByName("AwardPanel").getChildByName("desc").color = cc.color(158, 52, 224);
            break;
          case 2:
            var _i16 = undefined;
            var _s13 = undefined;
            _t69 = $2MyUtils.MyUtils.getRandomInt(4, 9) * $2UserDataManager.default.instance.chapter;
            20 == $2DataManager.default.instance.level && 3 == $2DataManager.default.instance.bossLevel && (_t69 *= 3);
            if (this.levelId >= 1 && this.levelId <= 5) {
              _i16 = Math.random() <= .8 ? 1 : 3;
            } else if (this.levelId >= 6 && this.levelId <= 10) {
              var _e107 = Math.random();
              _i16 = _e107 <= .5 ? 1 : _e107 > .5 && _e107 <= .9 ? 3 : 4;
            } else if (this.levelId >= 11 && this.levelId <= 15) {
              var _e108 = Math.random();
              _i16 = _e108 <= .3 ? 1 : _e108 > .3 && _e108 <= .6 ? 3 : _e108 > .6 && _e108 <= .9 ? 4 : 5;
            } else {
              var _e109 = Math.random();
              _i16 = _e109 <= .2 ? 1 : _e109 > .2 && _e109 <= .4 ? 3 : _e109 > .4 && _e109 <= .7 ? 4 : 5;
            }
            _s13 = $2MyUtils.MyUtils.getArrRandomValue($2DataManager.default.instance["rare" + _i16 + "Array"]);
            this.rewardPanel.children[_n57].getChildByName("AwardPanel").getChildByName("Icon").getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "PlantIcon/p_" + _s13, cc.SpriteFrame);
            this.rewardPanel.children[_n57].getChildByName("AwardPanel").getChildByName("chip").active = true;
            this.rewardPanel.children[_n57].getChildByName("AwardPanel").getChildByName("desc").getComponent(cc.Label).string = "碎片";
            this.rewardPanel.children[_n57].getChildByName("AwardPanel").getChildByName("desc").color = cc.color(255, 255, 255);
            this.rewardArray[_n57].chip[0] = _s13;
            this.rewardArray[_n57].chip[1] = _t69;
        }
        this.rewardPanel.children[_n57].getChildByName("AwardPanel").getChildByName("RewardNum").getComponent(cc.Label).string = "X" + _t69;
      }
      var t = $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.levelTable)[this.levelId].rewardType;
      var a = $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.levelTable)[this.levelId].rewardCount;
      switch (t) {
        case "a":
          $2UserDataManager.default.instance.gold += a;
          this.constPanel.getChildByName("GDReward").getComponentInChildren(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "ui/a034", cc.SpriteFrame);
          this.constPanel.getChildByName("GDReward").getComponentInChildren(cc.Label).string = "金币  X" + a;
          break;
        case "b":
          $2UserDataManager.default.instance.diamond += a;
          this.constPanel.getChildByName("GDReward").getComponentInChildren(cc.Label).string = "钻石  X" + a;
          break;
        default:
          this.constPanel.getChildByName("GDReward").active = false;
          this.constPanel.getChildByName("ChipReward").active = true;
          t = t.slice(1);
          $2UserDataManager.default.instance.setPlantChip(t, a);
          this.constPanel.getChildByName("ChipReward").getComponentInChildren(cc.Label).string = "X" + a;
          this.constPanel.getChildByName("ChipReward").getChildByName("PlantIcon").getComponent(cc.Sprite).spriteFrame = $2BundleManager.default.instance.getBundleRes("BundleTexture", "PlantIcon/p_" + t, cc.SpriteFrame);
      }
    }
  }, {
    key: "onClickCard",
    value: function onClickCard(e, t) {
      var _this201 = this;
      if (this.rewardGet) {
        return;
      }
      for (var _n58 = 0; _n58 < this.rewardPanel.childrenCount; _n58++) {
        this.rewardPanel.children[_n58].getChildByName("Title").active = false;
      }
      this.node.getChildByName("Panel").getChildByName("TitleLabel").active = false;
      this.rewardGet = true;
      var a = e.currentTarget;
      a.getComponent(cc.Animation).play();
      this.selectID = parseInt(t);
      a.getComponent(cc.Animation).on("stop", function () {
        a.getChildByName("Effect").active = true;
        _this201.scheduleOnce(_this201.showAll, .5);
      });
    }
  }, {
    key: "showAll",
    value: function showAll() {
      var _this202 = this;
      for (var _e110 = 0; _e110 < this.rewardPanel.childrenCount; _e110++) {
        if (_e110 != this.selectID) {
          this.rewardPanel.children[_e110].getComponent(cc.Animation).play();
          this.rewardPanel.children[_e110].getComponent(cc.Animation).on("stop", function () {
            _this202.btnPanel.active = true;
          });
        }
      }
    }
  }, {
    key: "onClickGetOne",
    value: function onClickGetOne() {
      $2UserDataManager.default.instance.gold += this.rewardArray[this.selectID].gold;
      $2UserDataManager.default.instance.diamond += this.rewardArray[this.selectID].diamond;
      $2UserDataManager.default.instance.setPlantChip(this.rewardArray[this.selectID].chip[0], this.rewardArray[this.selectID].chip[1]);
      $2UIManager.default.instance.closeUI("BowlingUI");
      $2UIManager.default.instance.closeUI("SuccessBowlingUI");
      $2UIManager.default.instance.showUI("MenuUI");
    }
  }, {
    key: "beishuReward",
    value: function beishuReward(e) {
      var _this203 = this;
      var t = Number(e);
      $2pvzChannel.pvzChannel.instance().showVideo({
        sucCall() {
          $2UserDataManager.default.instance.gold += _this203.rewardArray[e].gold * t;
          $2UIManager.default.instance.closeUI("SuccessUI");
          $2UIManager.default.instance.openUI("MenuUI");
        },
        failCall() {},
        endCall() {}
      });
    }
  }, {
    key: "onClickGetAll",
    value: function onClickGetAll() {
      var _this204 = this;
      if (!$2UserDataManager.default.instance.drawGuide && 2 == $2DataManager.default.instance.level || $2UserDataManager.default.instance.newUser) {
        $2UserDataManager.default.instance.drawGuide || 2 != $2DataManager.default.instance.level || ($2DataManager.default.instance.drawGuide = true);
        for (var _e111 = 0; _e111 < this.rewardArray.length; _e111++) {
          $2UserDataManager.default.instance.gold += this.rewardArray[_e111].gold;
          $2UserDataManager.default.instance.diamond += this.rewardArray[_e111].diamond;
          $2UserDataManager.default.instance.setPlantChip(this.rewardArray[_e111].chip[0], this.rewardArray[_e111].chip[1]);
        }
        $2UIManager.default.instance.closeUI("SuccessUI");
        $2UIManager.default.instance.openUI("MenuUI");
      } else {
        $2pvzChannel.pvzChannel.instance().showVideo({
          sucCall() {
            for (var _e112 = 0; _e112 < _this204.rewardArray.length; _e112++) {
              $2UserDataManager.default.instance.gold += _this204.rewardArray[_e112].gold;
              $2UserDataManager.default.instance.diamond += _this204.rewardArray[_e112].diamond;
              $2UserDataManager.default.instance.setPlantChip(_this204.rewardArray[_e112].chip[0], _this204.rewardArray[_e112].chip[1]);
            }
            $2UIManager.default.instance.closeUI("SuccessUI");
            $2UIManager.default.instance.openUI("MenuUI");
          },
          failCall() {},
          endCall() {}
        });
      }
    }
  }]);
  return b;
}(cc.Component);
def_SuccessBowlingUI = cc__decorate([ccp_ccclass], def_SuccessBowlingUI);
exports.default = def_SuccessBowlingUI;